
Object.defineProperty(exports, "__esModule", { value: true });
/**
* @module pub.message
* @author: Hjava
* @description: Pub模块消息内包
* @since: 2018-07-22 16:09:38
*/
var pub_constant_1 = __webpack_require__(/*! _pub/pub.constant */ "./src/core/pub/pub.constant.ts");
var bufferType_1 = __webpack_require__(/*! _util/bufferType */ "./src/core/utils/bufferType.ts");
var byteBuffer_1 = __webpack_require__(/*! _util/byteBuffer */ "./src/core/utils/byteBuffer.ts");
var constant_1 = __webpack_require__(/*! _util/constant */ "./src/core/utils/constant.ts");
var protocol_1 = __webpack_require__(/*! _util/protocol */ "./src/core/utils/protocol.ts");
var log_1 = __webpack_require__(/*! ./../utils/log */ "./src/core/utils/log.ts");
var PubMessage = {};
PubMessage.PubTextMessage = protocol_1.default.Message.extend({
    __category: 'PUB',
    __type: constant_1.MESSAGE_TYPE.MSG_TYPE_TEXT,
    uri: pub_constant_1.default.PUB.URI_PUB_TEXT_INFO,
    init: function () {
        this.text = '';
        this.font_name = 'serif';
        this.font_size = 12;
        this.bold = false;
        this.cipher_type = constant_1.CIPHER_TYPE.NO_CIPHER;
    },
    unmarshall: function () {
        this.text = this.popString();
        this.font_name = this.popString();
        this.font_size = this.popInt();
        this.bold = this.popBool();
        this.cipher_type = this.popShort();
    },
    marshall: function () {
        this.push(this.text);
        this.push(this.font_name);
        this.push(this.font_size);
        this.push(this.bold, bufferType_1.default.BOOLEAN);
        this.push(this.cipher_type, bufferType_1.default.SHORT);
    }
});
/**
 * 图片消息
 * @type {Function}
 */
PubMessage.PubImageMessage = protocol_1.default.Message.extend({
    __category: 'PUB',
    __type: constant_1.MESSAGE_TYPE.MSG_TYPE_IMAGE,
    uri: pub_constant_1.default.PUB.URI_PUB_IMAGE_INFO,
    init: function () {
        this.thumbnail = '';
        this.normal = '';
        this.original = '';
        this.type = '';
        this.token = '';
        this.originSize = 0;
        this.uploadImageType = 2;
        this.custom = '';
    },
    unmarshall: function () {
        this.thumbnail = this.popString();
        this.normal = this.popString();
        this.original = this.popString();
        this.type = this.popString();
        this.token = this.popString();
        this.originSize = this.popInt();
        this.uploadImageType = this.popByte();
        this.custom = this.popString();
    },
    marshall: function () {
        this.push(this.thumbnail, bufferType_1.default.STRING);
        this.push(this.normal, bufferType_1.default.STRING);
        this.push(this.original, bufferType_1.default.STRING);
        this.push(this.type, bufferType_1.default.STRING);
        this.push(this.token, bufferType_1.default.STRING);
        this.push(this.originSize, bufferType_1.default.INT);
        this.push(this.uploadImageType, bufferType_1.default.BYTE);
        this.push(this.custom, bufferType_1.default.STRING);
    }
});
/**
 * 单图文消息
 * @type {Function}
 */
PubMessage.PubLinkMessage = protocol_1.default.Message.extend({
    __category: 'PUB',
    __type: constant_1.MESSAGE_TYPE.MSG_TYPE_LINK,
    uri: pub_constant_1.default.PUB.URI_PUB_LINK_INFO,
    init: function () {
        this.title = '';
        this.image = '';
        this.content = '';
        this.link = '';
    },
    unmarshall: function () {
        this.title = this.popString();
        this.image = this.popString();
        this.content = this.popString();
        this.link = this.popString();
    },
    marshall: function () {
        this.push(this.title);
        this.push(this.image);
        this.push(this.content);
        this.push(this.link);
    }
});
/**
 * 多图文消息
 * @type {Function}
 */
PubMessage.PubMultiLinkMessage = protocol_1.default.Message.extend({
    __category: 'PUB',
    __type: constant_1.MESSAGE_TYPE.MSG_TYPE_MULTI_LINK,
    uri: pub_constant_1.default.PUB.URI_PUB_MULTI_LINK_INFO,
    init: function () {
        this.num = 0;
        this.content = '';
    },
    unmarshall: function () {
        this.num = this.popShort();
        this.content = this.popString();
    },
    marshall: function () {
        this.push(this.num, bufferType_1.default.SHORT);
        this.push(this.content);
    }
});
/**
 * 表情消息
 * @type {Function}
 */
PubMessage.PubEmotionMessage = protocol_1.default.Message.extend({
    __category: 'PUB',
    __type: constant_1.MESSAGE_TYPE.MSG_TYPE_EMOTION,
    uri: pub_constant_1.default.PUB.URI_PUB_EMOTION_INFO,
    init: function () {
        this.category = '';
        this.type = '';
        this.name = '';
    },
    unmarshall: function () {
        this.category = this.popString();
        this.type = this.popString();
        this.name = this.popString();
    },
    marshall: function () {
        this.push(this.category);
        this.push(this.type);
        this.push(this.name);
    }
});
/**
 * 事件消息
 * @type {Function}
 */
PubMessage.PubEventMessage = protocol_1.default.Message.extend({
    __category: 'PUB',
    __type: constant_1.MESSAGE_TYPE.MSG_TYPE_EVENT,
    uri: pub_constant_1.default.PUB.URI_PUB_EVENT_INFO,
    init: function () {
        this.type = '';
        this.text = '';
    },
    unmarshall: function () {
        this.type = this.popString();
        this.text = this.popString();
    },
    marshall: function () {
        this.push(this.type);
        this.push(this.text);
    }
});
/**
 * 日历消息
 * @type {Function}
 */
PubMessage.PubCalendarMessage = protocol_1.default.Message.extend({
    __category: 'PUB',
    __type: constant_1.MESSAGE_TYPE.MSG_TYPE_CALENDAR,
    uri: pub_constant_1.default.PUB.URI_PUB_CALENDAR_INFO,
    init: function () {
        this.dtstart = 0;
        this.dtend = 0;
        this.summary = '';
        this.location = '';
        this.trigger = '';
        this.participant = '';
        this.remark = '';
        this.calendarID = 0;
    },
    unmarshall: function () {
        this.dtstart = this.popLong().value();
        this.dtend = this.popLong().value();
        this.summary = this.popString();
        this.location = this.popString();
        this.trigger = this.popString();
        this.participant = this.popString();
        this.remark = this.popString();
        this.calendarID = this.popLong().value();
    },
    marshall: function () {
        this.push(this.dtstart, bufferType_1.default.LONG);
        this.push(this.dtend, bufferType_1.default.LONG);
        this.push(this.summary);
        this.push(this.location);
        this.push(this.trigger);
        this.push(this.participant);
        this.push(this.remark);
        this.push(this.calendarID, bufferType_1.default.LONG);
    }
});
/**
 * 语音消息
 * @type {Function}
 */
PubMessage.PubAudioMessage = protocol_1.default.Message.extend({
    __category: 'PUB',
    __type: constant_1.MESSAGE_TYPE.MSG_TYPE_VOICE,
    uri: pub_constant_1.default.PUB.URI_PUB_AUDIO_INFO,
    init: function () {
        this.url = '';
        this.codec = 0;
        this.duration = 0;
        this.stamp = 0;
        this.token = '';
        this.custom = '';
    },
    unmarshall: function () {
        this.url = this.popString();
        this.codec = this.popShort();
        this.duration = this.popShort();
        this.stamp = this.popLong().value();
        this.token = this.popString();
        this.custom = this.popString();
    },
    marshall: function () {
        this.push(this.url);
        this.push(this.codec, bufferType_1.default.SHORT);
        this.push(this.duration, bufferType_1.default.SHORT);
        this.push(this.stamp, bufferType_1.default.LONG);
        this.push(this.token);
        this.push(this.custom, bufferType_1.default.STRING);
    }
});
/**
 * 视频消息
 * @type {Function}
 */
PubMessage.PubVideoMessage = protocol_1.default.Message.extend({
    __category: 'PUB',
    __type: constant_1.MESSAGE_TYPE.MSG_TYPE_VIDEO,
    uri: pub_constant_1.default.PUB.URI_PUB_VIDEO_INFO,
    init: function () {
        this.videoUrl = '';
        this.screenshotUrl = 0;
        this.duration = 0;
        this.size = 0;
        this.width = 0;
        this.height = 0;
        this.timestamp = 0;
        this.token = '';
        this.custom = '';
    },
    unmarshall: function () {
        this.videoUrl = this.popString();
        this.screenshotUrl = this.popString();
        this.duration = this.popInt();
        this.size = this.popInt();
        this.width = this.popShort();
        this.height = this.popShort();
        this.timestamp = this.popLong().value();
        this.token = this.popString();
        this.custom = this.popString();
    },
    marshall: function () {
        this.push(this.videoUrl);
        this.push(this.screenshotUrl);
        this.push(this.duration);
        this.push(this.size);
        this.push(this.width, bufferType_1.default.SHORT);
        this.push(this.height, bufferType_1.default.SHORT);
        this.push(this.timestamp, bufferType_1.default.LONG);
        this.push(this.token);
        this.push(this.custom, bufferType_1.default.STRING);
    }
});
/**
 * 位置消息
 * @type {Function}
 */
PubMessage.PubGPSMessage = protocol_1.default.Message.extend({
    __category: 'PUB',
    __type: constant_1.MESSAGE_TYPE.MSG_TYPE_GPS,
    uri: pub_constant_1.default.PUB.URI_PUB_GPS_INFO,
    init: function () {
        this.uri = pub_constant_1.default.PUB.URI_PUB_GPS_INFO;
        this.latitude = 0;
        this.longitude = 0;
        this.name = '';
    },
    unmarshall: function () {
        this.latitude = this.popInt() / 1000000; //转换为实际数值
        this.longitude = this.popInt() / 1000000;
        this.name = this.popString();
    },
    marshall: function () {
        this.push(this.latitude * 1000000);
        this.push(this.longitude * 1000000);
        this.push(this.name);
    }
});
/**
 * VCard消息
 * @type {Function}
 */
PubMessage.PubVCardMessage = protocol_1.default.Message.extend({
    __category: 'PUB',
    __type: constant_1.MESSAGE_TYPE.MSG_TYPE_VCARD,
    uri: pub_constant_1.default.PUB.URI_PUB_VCARD_INFO,
    init: function () {
        this.uid = 0;
        this.name = '';
        this.account = '';
        this.type = 0;
        this.subtype = 0;
    },
    unmarshall: function () {
        this.uid = this.popLong().value();
        this.name = this.popString();
        this.account = this.popString();
        this.type = this.popShort();
        this.subtype = this.popShort();
    },
    marshall: function () {
        this.push(this.uid, bufferType_1.default.LONG);
        this.push(this.name);
        this.push(this.account);
        this.push(this.type, bufferType_1.default.SHORT);
        this.push(this.subtype, bufferType_1.default.SHORT);
    }
});
/**
 * 文件消息
 * @type {Function}
 */
PubMessage.PubFileMessage = protocol_1.default.Message.extend({
    __category: 'PUB',
    __type: constant_1.MESSAGE_TYPE.MSG_TYPE_FILE,
    uri: pub_constant_1.default.PUB.URI_PUB_FILE_INFO,
    init: function () {
        this.id = '';
        this.url = '';
        this.name = '';
        this.format = '';
        this.size = 0;
        this.token = '';
        this.lsize = 0;
        this.custom = '';
    },
    unmarshall: function () {
        this.id = this.popString();
        this.url = this.popString();
        this.name = this.popString();
        this.format = this.popString();
        this.size = this.popInt();
        this.token = this.popString();
        this.lsize = this.popLong().value();
        this.custom = this.popString();
    },
    marshall: function () {
        this.push(this.id);
        this.push(this.url);
        this.push(this.name);
        this.push(this.format);
        this.push(this.size);
        this.push(this.token);
        this.push(this.lsize, bufferType_1.default.LONG);
        this.push(this.custom);
    }
});
/**
 * 自定义消息
 * @type {Function}
 */
PubMessage.PubCustomMessage = protocol_1.default.Message.extend({
    __category: 'PUB',
    __type: constant_1.MESSAGE_TYPE.MSG_TYPE_CUSTOM,
    uri: pub_constant_1.default.PUB.URI_PUB_CUSTOM_INFO,
    init: function () {
        this.templateName = '';
        this.contentTitle = '';
        this.content = '';
        this.linkName = '';
        this.link = 0;
    },
    unmarshall: function () {
        this.templateName = this.popString();
        this.contentTitle = this.popString();
        this.content = this.popString();
        this.linkName = this.popString();
        this.link = this.popString();
    },
    marshall: function () {
        this.push(this.templateName);
        this.push(this.contentTitle);
        this.push(this.content);
        this.push(this.linkName);
        this.push(this.link);
    }
});
PubMessage.PubNoticeMessage = protocol_1.default.Message.extend({
    __category: 'PUB',
    __type: constant_1.MESSAGE_TYPE.MSG_TYPE_NOTICE,
    uri: pub_constant_1.default.PUB.URI_PUB_NOTICE_INFO,
    init: function () {
        this.title = '';
        this.image = '';
        this.content = '';
        this.link = '';
    },
    marshall: function () {
        this.push(this.title);
        this.push(this.image);
        this.push(this.content);
        this.push(this.link);
    },
    unmarshall: function () {
        this.title = this.popString();
        this.image = this.popString();
        this.content = this.popString();
        this.link = this.popString();
    }
});
/**
 * 群名片信息
 */
PubMessage.PubGVcardMessage = protocol_1.default.Message.extend({
    __category: 'PUB',
    __type: constant_1.MESSAGE_TYPE.MSG_TYPE_GVCARD,
    uri: pub_constant_1.default.PUB.URL_PUB_GVCARD_INFO,
    init: function () {
        this.guid = 0;
        this.name = '';
        this.account = '';
        this.type = 0;
        this.subtype = 0;
    },
    marshall: function () {
        this.push(this.guid, bufferType_1.default.LONG);
        this.push(this.name, bufferType_1.default.STRING);
        this.push(this.account, bufferType_1.default.STRING);
        this.push(this.type, bufferType_1.default.SHORT);
        this.push(this.subtype, bufferType_1.default.SHORT);
    },
    unmarshall: function () {
        this.guid = this.popLong().value();
        this.name = this.popString();
        this.account = this.popString();
        this.type = this.popShort();
        this.subtype = this.popShort();
    }
});
PubMessage.PubGeneralMessage = protocol_1.default.Message.extend({
    __category: 'PUB',
    __type: constant_1.MESSAGE_TYPE.MSG_TYPE_GENERAL,
    uri: pub_constant_1.default.PUB.URL_PUB_GENERAL_INFO,
    init: function () {
        this.data = [];
        this.type = 0;
        this.summary = '';
    },
    marshall: function () {
        this.push(byteBuffer_1.default.strToBytes(this.data), bufferType_1.default.BYTES);
        this.push(this.type, bufferType_1.default.INT);
        this.push(this.summary, bufferType_1.default.STRING);
    },
    unmarshall: function () {
        var buffer = this.popBytes();
        this.data = (new byteBuffer_1.default(buffer)).readUTF8String(buffer.byteLength);
        this.type = this.popInt();
        try {
            this.summary = this.popString();
        }
        catch (error) {
            log_1.default.error('IMGeneralMessage::unmarshall error summary:' + error);
            this.summary = '';
        }
    }
});
PubMessage.PubNewEmotionMessage = protocol_1.default.Message.extend({
    __category: 'PUB',
    __type: constant_1.MESSAGE_TYPE.MSG_TYPE_NEWEMOTION,
    uri: pub_constant_1.default.PUB.URI_PUB_NEWEMOTION_INFO,
    init: function () {
        this.category = '';
        this.packageId = '';
        this.packageName = '';
        this.id = '';
        this.name = '';
        this.type = '';
        this.params = '';
    },
    marshall: function () {
        this.push(this.category, bufferType_1.default.STRING);
        this.push(this.packageId, bufferType_1.default.STRING);
        this.push(this.packageName, bufferType_1.default.STRING);
        this.push(this.id, bufferType_1.default.STRING);
        this.push(this.name, bufferType_1.default.STRING);
        this.push(this.type, bufferType_1.default.STRING);
        this.push(this.params, bufferType_1.default.STRING);
    },
    unmarshall: function () {
        this.category = this.popString();
        this.packageId = this.popString();
        this.packageName = this.popString();
        this.id = this.popString();
        this.name = this.popString();
        this.type = this.popString();
        this.params = this.popString();
    }
});
/**
 * 引用消息
 */
PubMessage.PubQuoteMessage = protocol_1.default.Message.extend({
    __category: 'PUB',
    __type: constant_1.MESSAGE_TYPE.MSG_TYPE_QUOTE,
    uri: pub_constant_1.default.PUB.URI_PUB_QUOTE_INFO,
    init: function () {
        this.lastReply = '{}';
        this.quoted = '[]';
        this.searchText = '';
    },
    marshall: function () {
        this.push(this.lastReply, bufferType_1.default.STRING);
        this.push(this.quoted, bufferType_1.default.STRING);
        this.push(this.searchText, bufferType_1.default.STRING);
    },
    unmarshall: function () {
        try {
            this.lastReply = this.popString();
            this.quoted = this.popString();
            this.searchText = this.popString();
            var lastReplyMessage = JSON.parse(this.lastReply);
            lastReplyMessage = {
                message: protocol_1.default.Response.fromBase64(lastReplyMessage.message),
                defaultText: lastReplyMessage.defaultText
            };
            this.lastReplyMessage = lastReplyMessage;
            var quoted = JSON.parse(this.quoted);
            this.quotedMessage = quoted.map(function (item) {
                return {
                    message: protocol_1.default.Response.fromBase64(item.message),
                    defaultText: item.defaultText
                };
            });
        }
        catch (e) {
            log_1.default.error('IMQuoteMessage::unmarshall error info:' + e);
        }
    }
});
PubMessage.PubDynamicMessage = protocol_1.default.Message.extend({
    __category: 'PUB',
    __type: constant_1.MESSAGE_TYPE.MSG_TYPE_DYNAMIC,
    uri: pub_constant_1.default.PUB.URI_PUB_DYNAMIC_INFO,
    init: function () {
        this.id = '';
        this.title = '';
        this.dxData = '';
        this.appData = '';
    },
    marshall: function () {
        this.push(this.id, bufferType_1.default.LONG);
        this.push(this.title, bufferType_1.default.STRING);
        this.push(this.dxData, bufferType_1.default.STRING);
        this.push(this.appData, bufferType_1.default.STRING);
    },
    unmarshall: function () {
        this.id = this.popLong().value();
        this.title = this.popString();
        this.dxData = this.popString();
        this.appData = this.popString();
    }
});
exports.default = PubMessage;


//# sourceURL=webpack://MTDX/./src/core/pub/pub.message.ts?